package ink.lovejinhu.leetcode;

public class Solution_0482 {
    public String licenseKeyFormatting(String s, int k) {
        String s2 = s.toUpperCase().replaceAll("-", "");
        int flag=0;
        String res="";
        for (int i = s2.length() - 1; i >= 0; i--) {
           flag++;
           if (flag==k){
               if (i==0){
                   res=s2.substring(i, i+k)+res;
                   flag=0;
                   continue;
               }else {
                   res="-"+s2.substring(i, i+k)+res;
                   flag=0;
                   continue;
               }

           }
           if (i==0){
               res=s2.substring(i, i+flag)+res;
               break;
           }
        }
        return res;
    }

    public static void main(String[] args) {
        String s = "01234";
        System.out.println(s.substring(1, 2));
    }
}
